<template>
  <customizeDialog
    :visible.sync="isVisible"
    @close="onClose"
    title="审核"
    width="500px"
    top="40px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form
      ref="form"
      :model="checkForm"
      :rules="checkRules"
      label-width="80px"
      class="check-form"
    >
      <el-form-item label="审核结果" prop="checkStatus">
        <el-radio-group
          v-model="checkForm.checkStatus"
          :disabled="disabledCheckStatus"
        >
          <el-radio label="1">通过</el-radio>
          <el-radio label="0">退回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="审核意见">
        <el-input
          type="textarea"
          v-model="checkForm.content"
          :rows="4"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="onClose" :loading="btnLoading"
        >取消</el-button
      >
      <el-button
        @click="onCheck"
        type="primary"
        :loading="btnLoading"
        >确定</el-button
      >
    </template>
  </customizeDialog>
</template>
<script>
import customizeDialog from '@/components/checkHistory/customizeDialog'
import cacheUtil from '@/utils/cache'
import { addCheckInfo } from '@/api/reportManagement'
export default {
  components: {
    customizeDialog
  },
  data() {
    return {
      btnLoading: false,
      isVisible: false,
      checkForm: {
        // userName: cacheUtil.getItem('userName'),
        refId: '',
        checkStatus: '1',
        status: '',
        content: ''
      },

      disabledCheckStatus: false,
      checkRules: {},
      currentStatus: ''
    }
  },
  methods: {
    show(refId, status, disabled) {
      this.checkForm.refId = refId
      this.currentStatus = status
      this.disabledCheckStatus = disabled
      if (disabled) {
        this.checkForm.checkStatus = '0'
      }
      this.isVisible = true
    },
    onClose() {
      this.checkForm = {
        userName: cacheUtil.getItem('userName'),
        refId: '',
        content: '',
        checkStatus: '',
        status: ''
      }
      this.isVisible = false
    },
    onCheck() {
      this.btnLoading = true
      this.$refs.form.validate((valid) => {
        if (valid) {
          let formData = JSON.parse(
            JSON.stringify(this.checkForm)
          )
          if (formData.checkStatus === '1') {
            if (this.currentStatus === '3') {
              formData.status = '4'
            } else if (this.currentStatus === '4') {
              formData.status = '1'
            }
          } else {
            if (this.currentStatus === '1') {
              formData.status = '4'
            } else if (this.currentStatus === '4') {
              formData.status = '3'
            } else if (this.currentStatus === '3') {
              formData.status = '-1'
            } else if (
              this.currentStatus === '2' ||
              this.currentStatus === '-1'
            ) {
              formData.status = '0'
            }
          }
          addCheckInfo(formData).then((res) => {
            if (res.success) {
              this.$message.success('审核成功')
              this.onClose()
              this.$emit('success')
            } else {
              this.$message.error(res.message)
            }
            this.btnLoading = false
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep {
  .el-form-item__label {
    line-height: 40px !important;
  }
}

.cancel {
  width: 80px;
  height: 34px;
  border: 1px solid #497fa3;
  font-size: 14px;
  font-weight: 400;
  color: #497fa3;
}
.sumbit {
  width: 80px;
  height: 34px;
  background: #497fa3;
  box-shadow: 0px 0px 7px 0px rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 400;
  color: #ffffff;
}
</style>
